using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using SaveTheQueen;
using SaveTheQueen.Component;
using SaveTheQueen.Utils;
using Testbed.Tests;

namespace Testbed
{
    public class TestbedCore : Core
    {
        TextSprite footprint;
        List<Test> tests;
        int currentTest;

        public TestbedCore()
            : base()
        {
            footprint = new TextSprite("", "Font/Small", 20, 550, null, this);
            tests = new List<Test>();

            tests.Add(new MicLoopBackTest(this));
            tests.Add(new ActionTest(this));
            tests.Add(new AlingTest(this));
            tests.Add(new ColisionTest(this)); //3
            tests.Add(new ContainerTest(this));
            tests.Add(new EffectsTest(this));
            tests.Add(new GamepadImputTest(this));
            tests.Add(new KeyboardInputTest(this));
            tests.Add(new MouseTest(this));
            tests.Add(new SpriteTest(this)); // index = 9
            tests.Add(new ShaderTest(this));
            tests.Add(new BatchTest(this));

            currentTest = 11;
            ChangeTest(tests[currentTest]);
        }

        protected override void Update(GameTime gameTime)
        {
            if (KeyboardInput.Key(Keys.R) == Button.Down)
            {
                currentTest = (currentTest + 1) % tests.Count;
                ChangeTest(tests[currentTest]);
            }
            else if (KeyboardInput.Key(Keys.Q) == Button.Down)
            {
                currentTest = (currentTest - 1 < 0) ? tests.Count - 1 : currentTest - 1;
                ChangeTest(tests[currentTest]);
            }
            base.Update(gameTime);
        }

        private void ChangeTest(Test test)
        {
            footprint.Text = test.Name;
            this.Components.Remove(footprint);
            Core.ChangeScene(test);
            this.Components.Add(footprint); // ensure that the text is an overlay
        }
    }
}
